##  Used to check the truth of the rules from the rulebase.
#   These rules are used to check coordinates of the bony landmarks and sensors relative to eachother.
class Rule:

    ##  The constructor of Rule.
    def __init__(self, axis, ID1, ID2, ruleType):
        ##  The x, y or z axis.
        self.axis = axis
        ##  The first ID (bony landmark or sensor) to compare with ID2.
        self.ID1 = ID1
        ##  The second ID (bony landmark or sensor) to compare with ID1.
        self.ID2 = ID2
        ##  Bony landmark or sensor.
        self.ruleType = ruleType

    ##  Compares two objects and determines whether the positions of the measured objects are correct.
    #   @param[in]  positions   Either sensor instances or the globalPositions from the bony landmarks.
    #   @return[boolean]        True if the measurement is correct, else False.
    def IsTrue(self, positions):
        ##  Either sensor instances or the globalPositions from the bony landmarks.
        self.positions = positions
        # Order z x y!
        if self.axis=="z":
            return self.__GetPosition(self.ID1, 0) > self.__GetPosition(self.ID2, 0)
        elif self.axis=="x":
            return self.__GetPosition(self.ID1, 1) > self.__GetPosition(self.ID2, 1)
        elif self.axis=="y":
            return self.__GetPosition(self.ID1, 2) > self.__GetPosition(self.ID2, 2)
        else:
            print "error in Rule: invalid axis"
            return False

    ##  Returns the position of either a sensor or bony landmark depending on the ruletype.
    #   @param[in]  ID      A bony landmark or sensor ID.
    #   @param[in]  axis    The x, y or z axis.
    #   @return[array]      The position belonging to this axis.
    def __GetPosition(self, ID, axis):
        return self.positions[ID][axis][0,0]